2月 17 2015 Online Judge►UVa [UVa] 10583 - Ubiquitous Religions 很久沒有解題了,挑一題簡單的來做 XD 使用Union Find即可,我採用Quick Find,如果用Quick Union應該會更快。 1234567891011121314151617181920212223242526272829303132#include <iostream>using namespace std;int main(){ for ( int n , m , k = 0 ; cin >> n >> m && ( n != 0 && m != 0 ) ; k ++ ) { int student[50001] , total = n ; for ( int i = 1 ; i < n + 1 ; i ++ ) student[i] = i ; for ( int m2 = 0 , s1 ,s2 ; m2 < m && cin >> s1 >> s2 ; m2 ++ ) { int r = student[s2] ; if ( student[s1] == student[s2] ) continue ; else { for ( int i = 1 ; i < n + 1 ; i ++ ) { if ( student[i] == r ) { student[i] = student[s1] ; } } total -- ; } } cout << "Case " << k + 1 << ": " << total << endl ; } return 0;} Newer [Java] Huffman Coding實作壓縮軟體 Older [UVa] 100 - The 3n + 1 problem